//统一管理用户相关的接口
import request from '@/utils/request'  //引入二次封装的axios
import type {
    loginFormData, 
    loginResponseData, 
    UserInfoResponseData, 
    LogoutResponseData, 
    registerFormData, 
    registerResponseData,
    UserDetailResponseData,
    UpdateUserInfoData,
    ResponseData,
    UserEnrollmentsResponseData,
    UserClaimsResponseData
} from '@/api/user/type.ts'
//统一管理接口
enum Api {
    LOGIN_URL = '/user/login',
    REGISTER_URL = '/user/register',
    LOGIN_USER_INFO = '/user/info',
    LOGOUT_URL = '/user/logout',
    USER_DETAIL = '/user/detail',
    UPDATE_USER_INFO = '/user/update',
    USER_ENROLLMENTS = '/user/enrollments',
    USER_CLAIMS = '/user/claims',
}
//暴露请求函数
//登录接口方法
export const reqLogin = (data: loginFormData) => request.post<any,loginResponseData>(Api.LOGIN_URL, data);//第一个参数any表示请求体（request body）的类型，any也可以换成loginForm；第二个参数表示响应数据（response data）的类型
//注册接口方法
export const reqRegister = (data: registerFormData) => request.post<any,registerResponseData>(Api.REGISTER_URL, data);
//获取用户信息
export const reqUserInfo = () => request.get<any,UserInfoResponseData>(Api.LOGIN_USER_INFO);
//退出登录
export const reqLogout = () => request.get<any,LogoutResponseData>(Api.LOGOUT_URL);
//获取用户详细信息
export const reqUserDetail = () => request.get<any,UserDetailResponseData>(Api.USER_DETAIL);
//更新用户信息
export const reqUpdateUserInfo = (data: UpdateUserInfoData) => request.put<any,ResponseData>(Api.UPDATE_USER_INFO, data);
//获取用户报名的活动列表
export const reqUserEnrollments = () => request.get<any,UserEnrollmentsResponseData>(Api.USER_ENROLLMENTS);
//获取用户申领的失物列表
export const reqUserClaims = () => request.get<any,UserClaimsResponseData>(Api.USER_CLAIMS);

// 用户管理相关接口
// 获取用户列表
export const reqGetUserList = (params: any) => request.get('/admin/user/list', { params });
// 添加用户
export const reqAddUser = (data: any) => request.post('/admin/user/add', data);
// 更新用户
export const reqUpdateUser = (id: number, data: any) => request.put(`/admin/user/update/${id}`, data);
// 删除用户
export const reqDeleteUser = (id: number) => request.delete(`/admin/user/delete/${id}`);
